layui.use(['layer','table', 'form','laydate'], function () {
    var $ = layui.$;
    var table = layui.table;
    var laydate = layui.laydate;
    var form = layui.form;
    var layer = layui.layer;

    /*时间加载*/
    laydate.render({
        elem: '#test',
        type: 'date'
    });

    /*加载表格开始*/
    var MicroTable = table.render({
        elem:"#root",
        url:'/microLog/getAllMicroLog',
        toolbar:'#toptool',
        defaultToolbar:['print','filter','exports'],
        page:true,
        limit:15,
        limits:[10,20,30],
        cols:[[
            {type:'checkbox',align:'center',width:60},
            {type:'orderId',title:'序号',align:'center',width:60,templet:function (data) {
                    return data.LAY_INDEX;
                }},
            {field:'type',title:'操作类型',align:'center',templet:function (data) {
                    if (data.type=="2"){
                        data.type = "添加";
                    }else if (data.type=="3"){
                        data.type = "删除";
                    }else if(data.type=="4"){
                        data.type = "修改";
                    }else if(data.type=="5"){
                        data.type = "查找";
                    }
                    return "<p>"+data.type+"</p>";
                }},
            {field:'trueName',title:'执行人员',align:'center'},
            {field:'createDate',title:'执行时间',align:'center'},
            {field:'remark',title:'操作备注',align:'center'},
            {title:'操作',align:'center',templet:function (data) {
                    var tem = '<a  href="javascript:removeMicroLog('+data.logId+');" style="margin-left: 20px;color:rgb(13,171,158)">删除</a>';
                    return tem;
                }},
        ]]
    });
    /*加载表格结束*/

    /* 模糊查询开始 */
    form.on('submit(sub)',function (data) {
        MicroTable.reload({
            url:'/microLog/getAllMicroLog?trueName='+data.field.trueName+'&createDate='+data.field.createDate
        });
        return false;
    });
    /* 模糊查询结束 */

    /* 重置 */
    form.on('submit(subs)',function (data) {
        MicroTable.reload({
            url:'/microLog/getAllMicroLog'
        });
    });
    /* 重置结束 */

    /* 删除开始 */
    removeMicroLog = function removeMicroLog(logId){
        console.log(logId);
        layer.confirm("确定删除？",{btn: ['确定', '取消'],title:"提示"}, function() {
            $.ajax({
                url: '/microLog/delMicroLog',
                data: {'logId': logId},
                dataType: 'json',
                type:'post',
                success: function (data) {
                    layer.msg("删除成功");
                }
            })
        });
    }
    /* 删除结束 */


    Refresh = function Refresh() {
        location.reload();
    }

    //返回
    goBack = function goBack() {
        parent.$('#beforeHref').val($('.layui-elem-quote').children('span').eq(0).text());
        parent.before();
        return false;
    }
});